﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.Geometry;
using System.Data.SQLite;
using CCWin;

namespace BS_2
{
    public partial class Form_Login : Form
    {
        public Form_Login()
        {
            InitializeComponent();
        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }
        //实现关闭form
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
        //实现登录
        private void button1_Click(object sender, EventArgs e)
        {
            
            string sql = "select * from db_user where user_name ='" + textBox1.Text + "' and user_password ='" + textBox2.Text + "'";
            string str = DataAccess.Get_Row1_Col1_Value(sql);
            //MessageBox.Show(str);
            if (str!="")
            {
                MessageBoxEx.Show("登录成功");
                Form1 main = new Form1();
                main.Show();
                //this.Hide();
            }
            else
            {
                MessageBoxEx.Show("登录失败，没有查询到账户信息");

            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string sql = "select * from db_user where user_name='" + textBox1.Text + "'";
            int i = DataAccess.Run_SQL(sql);
            if (i == 1)
            {
                MessageBoxEx.Show("对不起，该账户已经存在！");
                
            }

            else
            {
                sql = "insert into db_user(user_name,user_password) values('" + textBox1.Text + "','" + textBox2.Text + "')";
                i = DataAccess.Run_SQL(sql);
                if (i == 1)
                {
                    MessageBoxEx.Show("注册成功");

                }
                else
                {
                    MessageBoxEx.Show("注册失败，请重新注册");

                }

            }
            
        }
    }
}
